from django.db import models

from TestInterface.models import TestInterfaceCaseModel
from Testproject.models import TestProjectModel


# Create your models here.


class TestScene(models.Model):
    """
    | 字段      | 类型         | 空   | 默认  | 注释      |
    |:------- |:---------- |:--- | --- | ------- |
    | id      | int        | 否   |     | 自增长主键ID |
    | project | ForeignKey | 否   |     | 关联项目    |
    | name    | varchar    | 否   |     | 业务流名称   |

    """
    project = models.ForeignKey(TestProjectModel, on_delete=models.CASCADE, verbose_name="关联项目",
                                help_text="关联项目")
    name = models.CharField(max_length=50, verbose_name="业务流名称", help_text="业务流名称")

    def __str__(self):
        return self.name

    class Meta:
        db_table = "test_scene"
        verbose_name_plural = "业务流测试表"


class TestSceneToCase(models.Model):
    """
    | 字段    | 类型         | 空   | 默认  | 注释          |
    |:----- |:---------- |:--- | --- | ----------- |
    | id    | int        | 否   |     | 自增长主键ID     |
    | icase | ForeignKey | 否   |     | 接口用例        |
    | scene | ForeignKey | 否   |     | 业务流         |
    | sort  | int        | 是   |     | 业务流中的用例执行顺序 |


    """
    icase = models.ForeignKey(TestInterfaceCaseModel, on_delete=models.PROTECT, verbose_name="接口用例",
                              help_text="接口用例")
    scene = models.ForeignKey(TestScene, on_delete=models.PROTECT, verbose_name="业务流", help_text="业务流")
    sort = models.IntegerField(null=True, blank=True, verbose_name="业务流中的用例执行顺序",
                               help_text="业务流中的用例执行顺序")

    def __str__(self):
        return self.icase.title

    class Meta:
        db_table = "scene_to_case"
        verbose_name_plural = "业务流和接口用例的中间表"
